import request from '../utils/request';
import {getToken} from "../utils/authority";
import {stringify} from 'qs';

export async function query() {
  return request('/api/users');
}

export async function getUserInfo() {
  return request('/admin/user/info', {
    headers: {
      'Authorization': `Bearer ${getToken()}`,
    }
  });
}

export async function fakeAccountLogin(params) {
  return request(`/auth/oauth/token?${stringify(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json; charset=utf-8',
      'Authorization': 'Basic cGlnOnBpZw==',
    },
  });
}

export async function fakeLogout(params) {
  return request(
    `/auth/authentication/removeToken?${stringify(params)}`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8',
        'Authorization': `Bearer ${getToken()}`,
      },
    })
}

export async function fakeRegister(params) {
  return request('/api/register', {
    method: 'POST',
    body: params,
  });
}
